Repository navigation
Media modal: Show the fields registered for attachments - #86457
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @padams! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
dcd6efd to
03d8c57
Compare
|
Passing in fields to the media upload modal from the Thanks again for your help with these! |
03d8c57 to
475774b
Compare
|
Rebased onto trunk after #86458. The only conflicts were in the media-utils changelog and the modal's test file, where both PRs added lines in the same spot, so I kept both sets. The code is unchanged, and CI is green on 475774b. |
andrewserong
left a comment
There was a problem hiding this comment.
This is testing nicely for me for the filter use case:
2026-11-11.15.22.09.mp4
Something I noticed while testing (and this also applies to the post-list) is that by default registered fields will show up in the sort by list, but the attachments REST API endpoint doesn't support it by default:
A couple of options for plugins:
- When registering fields, set
enableSortingtofalse, or: - Also use the
rest_attachment_collection_paramsandrest_attachment_queryfilters to make sure the fields are accepted in the orderby value and then passed along appropriately to the query
Something that'll be interesting to do dig into further down the track is how much the fields registration API should handle automatically for attachments so that plugins don't need to do so much plumbing to get things working.
In any case, this'll also be interesting stuff to play with for media folders, too.
Thanks again for the work here, I'll merge it in!
What?
See #74865, #75123
The DataViews media modal shows the fields registered for attachments on the server, alongside its own, as columns and filters.
Why?
The modal's fields are a fixed list in
MediaUploadModal. A field a plugin registers forpostType/attachmentwithwp_register_entity_fields()shows in the media editor, which reads the registry, but not in the modal. A plugin that adds attachment taxonomies, credits or license fields has no way to let people filter or see them where they pick media.How?
MediaUploadModaltakes an optionalfieldsprop. Registered fields are added after the modal's own. A registered field with the ID of one of the modal's own is left out, because those carry behavior specific to the modal: the thumbnail can't be hidden, and "Attached to" has options for the current post. The core attachment collection registers the same IDs, so nothing changes for core's fields.media-utilshas no dependency oneditor, so the editor'seditor.MediaUploadwrapper supplies them, as it already supplies the current post. It readsgetEntityFields( 'postType', 'attachment' )only while the modal is open, so the fields are requested the first time the modal opens, not wherever a media placeholder renders.The
MediaEditcomponents infieldsandmedia-utilsalso render the modal and don't pass registered fields yet. That can follow once this approach is agreed.Testing Instructions
With only this PR, the Genres filter shows but doesn't change the results yet: the modal's query doesn't know about taxonomy fields. #86458 does that.
Testing Instructions for Keyboard
The filter and column use DataViews' own controls, so keyboard use is the same as for the modal's other filters: tab to "Add filter", open it with Enter, and choose Genres with the arrow keys.
Use of AI Tools
Written with Claude Code (Claude Opus 5.5) and reviewed by me.